package son.nt.act4;

import son.nt.R;
import son.nt.act2.FileActivity;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.RemoteViews;

public class NotificationActivity extends Activity{
	
	private NotificationManager notiManager = null;
	private Notification noti1 = null;
	private Notification noti2 = null;
	private Context mContext = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notification_activity);
		mContext = this;
		notiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
		
		//noti 1
		int icon = R.drawable.newtab_area_on;
		CharSequence title = "noti default";
		long time = System.currentTimeMillis();
		noti1 = new Notification(icon, title, time);
		Intent intent1 = new Intent(mContext, FileActivity.class);
		intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		PendingIntent pending = PendingIntent.getActivity(mContext, 1, intent1, 1);
		noti1.setLatestEventInfo(mContext, "Nguyen thanh son", "NEC VN ", pending);
		
		//noti 2 - notification custom
		noti2 = new Notification(icon, title, time);
		noti2.contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
		noti2.contentIntent = pending;
		
	}
	
	public void onClick(View v){
		switch (v.getId()) {
		case R.id.btnShownoti:
			showNofi1();
			break;
		case R.id.btnDisnableNoti:
			showNofi2();
			break;
		case R.id.btnShownoti2:
			showNofi3();
			break;
		case R.id.btnDisnableNoti2:
//			notiManager.cancel(2);
//			showNofi3();
			break;

		default:
			break;
		}
	}
	
	public void showNofi1(){
		notiManager.notify(1, noti1);
	}
	
	public void showNofi2(){
		notiManager.notify(2, noti2);
	}
	public void showNofi3() {
		Notification.Builder builder = new Notification.Builder(mContext);
		builder.setSmallIcon(R.drawable.newtab_area_on)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
		Intent intent1 = new Intent(mContext, FileActivity.class);
		intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		PendingIntent pending = PendingIntent.getActivity(mContext, 1, intent1, 1);
		Notification notification=  builder.getNotification();
		int id = getResources().getSystem().getIdentifier("status_bar_latest_event_content", "id", "android");
		notification.contentIntent = pending;
		RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
		notification.contentView.addView(id, contentView);
		notiManager.notify(3, notification);
	}
	public void showNofi4() {
		NotificationCompat.Builder mBuilder =
	        new NotificationCompat.Builder(this)
	        .setSmallIcon(R.drawable.newtab_area_on)
	        .setContentTitle("My notification")
	        .setContentText("Hello World!");
	// Creates an explicit intent for an Activity in your app
	Intent resultIntent = new Intent(this, FileActivity.class);

	// The stack builder object will contain an artificial back stack for the
	// started Activity.
	// This ensures that navigating backward from the Activity leads out of
	// your application to the Home screen.
	TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
	// Adds the back stack for the Intent (but not the Intent itself)
	stackBuilder.addParentStack(FileActivity.class);
	// Adds the Intent that starts the Activity to the top of the stack
	stackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent =
	        stackBuilder.getPendingIntent(
	            0,
	            PendingIntent.FLAG_UPDATE_CURRENT
	        );
	mBuilder.setContentIntent(resultPendingIntent);
	NotificationManager mNotificationManager =
	    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	// mId allows you to update the notification later on.
	mNotificationManager.notify(7, mBuilder.getNotification());
	}
}
